package com.ruoyi.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.plus.web.controller.BasePlusController;
import com.ruoyi.common.core.plus.web.page.PageDto;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.utils.SecurityUtils;

import com.ruoyi.system.domain.LanguageType;
import com.ruoyi.system.domain.params.LanguageTypeParams;
import com.ruoyi.system.domain.vo.LanguageTypeVo;
import com.ruoyi.system.service.ILanguageTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 语言类型Controller
 *
 * @author huyafang
 * @date 2023-03-06
 */
@RestController
@RequestMapping("/system/manage/language_type")
@Api(tags = "语言类型")
public class LanguageTypeController extends BasePlusController {
    @Autowired
    private ILanguageTypeService languageTypeService;

    /**
     * 查询语言类型列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "分页")
    public TableDataInfo<LanguageTypeVo> list(LanguageTypeParams languageTypeParams) {
        PageDto pageDto = startPage();
        Page<LanguageTypeVo> page = new Page<>(pageDto.getCurrentPage(), pageDto.getPageSize());
        IPage<LanguageTypeVo> list = languageTypeService.queryList(page, languageTypeParams);
        return getDataTable(list);
    }


    /**
     * 获取语言类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('coin-trade:common:language_type:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "查看")
    public R getInfo(@PathVariable("id") Long id) {
        return R.ok(languageTypeService.getById(id));
    }

    /**
     * 新增语言类型
     */
    @PreAuthorize("@ss.hasPermi('coin-trade:common:language_type:add')")
    @Log(title = "语言类型", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增")
    public R add(@RequestBody LanguageType languageType) {
        if (StringUtils.isEmpty(languageType.getApplicationCode())) {
            return R.fail("项目编号不能为空");
        }
        languageTypeService.saveLanguageType(languageType, SecurityUtils.getUsername());
        return R.ok();
    }

    /**
     * 修改语言类型
     */
    @PreAuthorize("@ss.hasPermi('coin-trade:common:language_type:edit')")
    @Log(title = "语言类型", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改")
    public R edit(@RequestBody LanguageType languageType) {
        return R.ok(languageTypeService.updateLanguageType(languageType));
    }

    /**
     * 删除语言类型
     */
    @PreAuthorize("@ss.hasPermi('coin-trade:common:language_type:remove')")
    @Log(title = "语言类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除")
    public R remove(@PathVariable Long[] ids) {
        return R.ok(languageTypeService.deleteByIds(ids));
    }

}
